/************************************************************************
 * The code is owned by mainframer.cn and Shang Tao
 * Without aproval of mainframer.cn and Shang Tao, removing the copyright
 * infomation is regarded as invassion of proprietary copyright
 ***********************************************************************/
package com.mr.qa.dao.impl;

import java.util.Date;
import java.util.List;

import junit.framework.TestCase;

import org.hibernate.Transaction;

import com.mr.qa.bo.Question;
import com.mr.qa.bo.QuestionCategory;
import com.mr.qa.bo.User;
import com.mr.qa.util.HibernateSessionFactory;

public class QuestionDAOTest extends TestCase {

	public QuestionDAOTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testSave() {
		QuestionCategoryDAO categoryDAO = new QuestionCategoryDAO();
		QuestionDAO questionDAO = new QuestionDAO();
		UserDAO userDAO = new UserDAO();
		Transaction tx = null;
		try {
			tx = HibernateSessionFactory.getSession().beginTransaction();
			
			User user = userDAO.findById(new Integer(4));
			
			QuestionCategory category = categoryDAO.findById(new Integer(2));
			category.setName("n1");
			QuestionCategory category2 = (QuestionCategory)categoryDAO.findByExample(category).get(0);
			Question question = new Question();
			question.setMrIaskCategory(category2);
			question.setTitle("tttt");
			question.setContent("ccc");
			question.setState("1");
			question.setIsPoll("0");
			question.setPostDate(new Date());
			question.setMrIaskUser(user);
			questionDAO.save(question);
			
			tx.commit();

		} catch (RuntimeException re) {
			re.printStackTrace();
		} finally {
			if (tx != null) {
				tx.rollback();
			}
		}
		
	}
	
	public void testFindAll() {
		QuestionDAO questionDAO = new QuestionDAO();
		UserDAO userDAO = new UserDAO();
		Transaction tx = null;
		try {
			//tx = HibernateSessionFactory.getSession().beginTransaction();
			User user = userDAO.findById(new Integer(4));
			
			questionDAO.setPage(new Integer(1), new Integer(2));
			
			List list = questionDAO.findByProperty("mrIaskUser", user);
			
			for(int i = 0; i < list.size(); i++){
				Question question = (Question)list.get(i);
				System.out.println(question.getId());
			}
			
			
			
			//tx.commit();
		} catch (RuntimeException re) {
			re.printStackTrace();
		} finally {
			if (tx != null) {
				tx.rollback();
			}
		}
	}

	public void testDelete() {
		fail("Not yet implemented");
	}

	public void testFindById() {
		fail("Not yet implemented");
	}

	public void testFindByExample() {
		fail("Not yet implemented");
	}

	public void testFindByProperty() {
		fail("Not yet implemented");
	}

	public void testFindByTitle() {
		fail("Not yet implemented");
	}

	public void testFindByReference() {
		fail("Not yet implemented");
	}

	public void testFindByContent() {
		fail("Not yet implemented");
	}

	public void testFindByAddition() {
		fail("Not yet implemented");
	}

	public void testFindByFile() {
		fail("Not yet implemented");
	}

	public void testFindByState() {
		fail("Not yet implemented");
	}

	public void testFindByIsPoll() {
		fail("Not yet implemented");
	}

	public void testFindByIsAnonymous() {
		fail("Not yet implemented");
	}

	public void testFindByViewCount() {
		fail("Not yet implemented");
	}

	public void testMerge() {
		fail("Not yet implemented");
	}

	public void testAttachDirty() {
		fail("Not yet implemented");
	}

	public void testAttachClean() {
		fail("Not yet implemented");
	}

}
